package top.hkyzf.study.leetcode.bit;

import org.junit.Test;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/6 0006 16:11
 * @version V1.0
 */
public class 找出数组中的_K_or值_2917 {
    public int findKOr(int[] nums, int k) {
        int rtn = 0;
        for (int i = 0; i < 31; i++) {
            int temp = 0;
            int tt = 0;
            for (int j = 0; j < nums.length; j++) {
                if ((nums[j] & 1) == 1) {
                    temp++;
                }
                nums[j] = nums[j] >> 1;
                if (nums[j] == 0) {
                    tt++;
                }
            }
            if (temp >= k) {
                rtn += 1<<i;
            }
            if (tt == nums.length) {
                break;
            }
        }
        return rtn;
    }

    @Test
    public void testFindKOr () {
        int[] nums = {7,12,9,8,9,15};
        int k = 4;
        System.out.println(findKOr(nums, k));
    }
}
